<template>
	<view class="page">
		<u-navbar :title='title' :autoBack="true" bgColor="transparent"></u-navbar>
		<image
			src="https://renovationcdn.jiachuangnet.com/person/p-bg.png"
			class='bg' style=""></image>
		<view class="avatar_box" >
			<view v-if="insertTalentForm.avatar&&insertTalentForm.avatar.length" @click="viewImgChoose(4)" style="margin-bottom: 30rpx; width: 153rpx;height:153rpx;border-radius: 50%;border: 5rpx solid #fff;overflow: hidden">
				<image :src="'https://'+insertTalentForm.avatar" mode="" style="width: 100%;height:100%;"></image>
			</view>
			<view v-else style="margin-bottom: 30rpx; width: 153rpx;height:153rpx;border-radius: 50%;border: 5rpx solid #fff;overflow: hidden" @click="uploadShow(4)">
				<image src="https://renovationcdn.jiachuangnet.com/mine/avatar.png"
					style="width: 100%;height:100%;"></image>
			</view>
			<image v-if="!isEdit" src="https://renovationcdn.jiachuangnet.com/person/poto.png" mode="" style="width: 71rpx;height:71rpx;z-index: 9999; position: absolute;bottom: 50rpx;right: 0;"></image>
			<text style="font-size: 32rpx;color: #1E272E;" v-if="!isEdit||(isEdit&&insertTalentForm.state==2)">上传头像</text>
			<upload :isreLoad="true" ref="avatar" name='avatar' :maxCount="1" @uploadFile="uploadFile($event,'avatar')" v-show="false"></upload>
		</view>
		<view class="container">
			<view class="info_box" >
				<view class="info_title flex" style="margin-right: unset;">
					<view class="flex" style="align-items: center;justify-content: center;">
						<view class="boder-left" style="margin-right: 20rpx;"></view>
						基本信息
						<view v-if="talentState" style="margin-left: 20rpx;">
							<view  v-if="talentState==1">
								<u-tag text="已认证" type="success"  shape="circle" plain size="mini"></u-tag>
							</view>
							<view  v-if="talentState==2" class="flex">
								<u-tag text="待审核" type="warning"  shape="circle" plain size="mini"></u-tag>
								<!-- <text>申请未审核,请耐心等待:)'</text> -->
							</view>
							<view  v-if="talentState==3" class="flex">
								<u-tag text="已驳回" type="error" shape="circle" plain size="mini"></u-tag>
								<!-- <text>申请已驳回,请重新修改个人信息后再申请:)</text> -->
							</view>
							<view  v-if="talentState==4" class="flex">
								<u-tag text="已禁用" type="error" shape="circle" plain size="mini"></u-tag>
								<!-- <text>账号被禁用,请联系管理员:)</text> -->
							</view>
						</view>
					</view>
				</view>
						
						<!-- 注意，如果需要兼容微信小程序，最好通过setRules方法设置rules规则 -->
						<view class="flex alignItem bewteen">
							<view class="label" style="width:150rpx"><text style="color:red;margin-right: 10rx;">*</text>真实姓名</view>
							<view class="val flex" style="align-items: center;">
								<u--input
										type="text"
										:disabled="true"
										v-model="insertTalentForm.nickName"
										border="none"
										placeholder="无需填写"
										placeholderClass="placeholder"
								></u--input>
								 <view style="width: 45%;">
								 	<u-radio-group
									:disabled="isEdit&&insertTalentForm.state!=2"
								 	   v-model="insertTalentForm.sex"
								 	   placement="row"
								 	 >
								 	   <u-radio
								 	     :customStyle="{marginBottom: '8px'}"
								 	     v-for="(item, index) in sexList"
								 	     :key="index"
								 	     :label="item.name"
								 	     :name="item.name"
								 	   >
								 	   </u-radio>
								 	 </u-radio-group>
								 </view>
							</view>
						</view> 
						<view class="flex alignItem bewteen">
							<view class="label" style="width:200rpx"><text style="color:red;margin-right: 10rx;">*</text>微信ID</view>
							<view class="val">
								<u--input
										v-model="insertTalentForm.wechatId"
										border="none"
										placeholder="请输入微信ID"
										:disabled="isEdit&&insertTalentForm.state!=2"
								></u--input>
							</view>
						</view>
						<!-- <view class="flex alignItem bewteen">
							<view class="label" style="width:200rpx"><text style="color:red;margin-right: 10rx;">*</text>密码</view>
							<view class="val">
								<u--input
										v-model="insertTalentForm.password"
										border="none"
										type='password' 
										clearable
										placeholder="请输入密码"
								></u--input>
							</view>
						</view> -->
						<!-- <view class="flex alignItem bewteen">
							<view class="label" style="width:160rpx"><text style="color:red;margin-right: 10rx;">*</text>性别</view>
							<uni-data-select   style="width: 250rpx"  v-model="insertTalentForm.sex" :localdata="sexList"></uni-data-select>
						</view> -->
						<view class="flex alignItem bewteen">
							<view class="label" style="width:160rpx"><text style="color:red;margin-right: 10rx;">*</text>申请岗位</view>
							<view class="val" style="overflow: visible;">
								<uni-data-select :disabled="isEdit&&insertTalentForm.state!=2" placeholder="请选择您的岗位"  style="width: 250rpx;"  v-model="insertTalentForm.roleId" :localdata="roleList"></uni-data-select>
							</view>
						</view>
						<view class="flex alignItem bewteen">
							<view class="label" style="width:200rpx"><text style="color:red;margin-right: 10rx;">*</text>年龄</view>
							<view class="val">
								<u--input
								:disabled="isEdit&&insertTalentForm.state!=2"
										v-model="insertTalentForm.age"
										border="none"
										placeholder="请输入年龄"
										type="number"
								></u--input>
							</view>
						</view>
						<view class="flex alignItem bewteen">
							<view class="label" style="width:200rpx"><text style="color:red;margin-right: 10rx;">*</text>工龄</view>
							<view class="val">
								<u--input
								:disabled="isEdit&&insertTalentForm.state!=2"
										v-model="insertTalentForm.workYears"
										border="none"
										placeholder="请输入工龄"
										type="number"
								></u--input>
							</view>
						</view>
						<view class="flex alignItem bewteen">
							<view class="label" style="width:200rpx"><text style="color:red;margin-right: 10rx;">*</text>手机号码</view>
							<view class="val">
								<u-input type="number" :disabled="true"  placeholder="请输入您的手机号码" v-model="insertTalentForm.phoneNumber"></u-input>
							</view>
						</view>
						
						<view class="flex alignItem bewteen" v-if="0">
							<view class="label" style="width:200rpx"><text style="color:red;margin-right: 10rx;">*</text>验证码</view>
							<view class="val flex" style="align-items: center;">
								<u--input
								:disabled="isEdit&&insertTalentForm.state!=2"
										v-model="insertTalentForm.code"
										border="none"
										placeholder="请输入验证码"
								></u--input>
								<view class="boder_left">
								</view>
								<view >
									<u-toast ref="uToast"></u-toast>
									<u-code :seconds="seconds" changeText='倒计时X秒' ref="uCode"
										@change="codeChange"></u-code>
									<text style="font-size: 28rpx;color: #F79E1B;" @tap="getCode">{{tips}}</text>
								</view>
							</view>
						</view>
						<!-- <view class="flex alignItem bewteen">
							<view class="label" style="width:200rpx"><text style="color:red;margin-right: 10rx;">*</text>证件号</view>
							<view class="val">
								<u--input
										v-model="insertTalentForm.idCard"
										border="none"
										placeholder="请输入身份证件号"
								></u--input>
							</view>
						</view> -->
						<view class="flex alignItem bewteen">
							<view class="label" style="width:200rpx"><text style="color:red;margin-right: 10rx;">*</text>居住地址</view>
							<view class="val" @click='map'>
								<view class="flex" style="flex: 1;">
									<u--input
											
											v-model="insertTalentForm.address"
											border="none"
											disabled
											placeholder="请选择居住地址"
									></u--input>
									<u-icon name="map" size="24" color='#13989A'></u-icon>
								</view>
							</view>
						</view>

						<view class="flex alignItem bewteen" style="align-items: flex-start;">
							<view class="label" style="width:200rpx;margin-top: 30rpx;">简介</view>
							<view class="val introduce_text" style="border-bottom: unset;">
								<u--textarea :disabled="isEdit&&insertTalentForm.state!=2" v-model="insertTalentForm.introduction" placeholder="请输入个人简介" ></u--textarea>
							</view>
						</view>

							
						
				</view>
				<view class="certificates_unload" >
					<view class="info_title flex">
						<view class="boder-left"></view>
						证件信息
					</view>
					<view class="flex" style="justify-content: space-around;padding: 40rpx 0;">
						<image @click="viewImgChoose(1)" v-if="insertTalentForm.frontImg&&insertTalentForm.frontImg.length" :src="'http://'+insertTalentForm.frontImg" mode="" style="width: 310rpx;height: 256rpx;"></image>
						<image @click="uploadShow(1)" v-else src="https://renovationcdn.jiachuangnet.com/person/p-p1.png" mode="" style="width: 310rpx;height: 256rpx;"></image>
						<image @click="viewImgChoose(2)" v-if="insertTalentForm.backImg&&insertTalentForm.backImg.length" :src="'http://'+insertTalentForm.backImg" mode="" style="width: 310rpx;height: 256rpx;"></image>
						<image @click="uploadShow(2)" v-else src="https://renovationcdn.jiachuangnet.com/person/p-p2.png" mode="" style="width: 310rpx;height: 256rpx;"></image>
						<upload :isreLoad="true" ref="frontImg" name='idCardImg' :maxCount="1" @uploadFile="uploadFile($event,'frontImg')" v-show="false"></upload>
						<upload :isreLoad="true" ref="backImg" name='idCardImg' :maxCount="1" @uploadFile="uploadFile($event,'backImg')" v-show="false"></upload>
					</view>
					
				</view>
				<view class="experience_box">
					<view class="flex" style="align-items: center;margin-top: 30rpx;">
						<view class="info_title flex" style="margin: unset; ">
							<view class="boder-left" style="margin-right: 16rpx;"></view>
							项目经验
						</view>
						<u-icon v-if="!isEdit||(isEdit&&insertTalentForm.state!=0)" @click="showAddExperience=true" name="plus-circle-fill" color="#13989A" size="24"></u-icon>
					</view>
					<view class="experience_wrapper">
						<view class="experience_item" @click="experienceEdit(index,item.projectId)" v-for=" (item,index) in insertTalentForm.projectDetail" :key="index">
							<view class="experience_item_title flex">
								<view class="experience_item_projectName">
									{{item.projectName}}
								</view>
								<view class="experience_item_time flex" >
									{{`${item.startTime}至${item.endTime}`}}
									<view style="margin-left:10rpx;">
										<u-icon name="arrow-right" ></u-icon>
									</view>
								</view>
								
							</view>
							<view class="experience_item_content">
								<text>
									{{item.content}}
								</text>
							</view>
						</view>
					</view>
					
				</view>
				<view class="certificates_unload" >
					<view class="info_title flex" style="margin-right: 430rpx;">
						<view class="boder-left"></view>
						从业资格证书
					</view>
					<view style="padding: 40rpx 0;">
						<view class="flex" v-if="!insertTalentForm.certificateImg.length">
							<image  src="https://renovationcdn.jiachuangnet.com/person/eg.png" mode="" style="width: 310rpx;height: 228rpx;"></image>
							<view class="post_image_box"  @click="uploadShow(3)" v-if="!isEdit||insertTalentForm.state==2">
								<image src="https://renovationcdn.jiachuangnet.com/person/p-img2.png" mode="" style="width: 114rpx;height: 93rpx;"></image>
							</view>
						</view>
						<view class="flex" v-else style="flex-wrap: wrap;">
							<view style="width: 310rpx;height: 228rpx; position: relative;" @click="preImgList(index)" v-for="(url,index) in insertTalentForm.certificateImg" :key="index">
								<image :src="'http://'+url" mode="" style="width: 310rpx;height: 228rpx;"></image>
								<view style="position: absolute;right: 0;bottom: 0;" v-if="!isEdit||insertTalentForm.state==2" @click.stop="deleteImg(index)">
									<u-icon name="trash-fill" color="#13989a" size="26" style="position: absolute;right: 0;top: 0;"></u-icon>
								</view>
							</view>
							<view class="post_image_box" @click="uploadShow(3)" v-if="!isEdit||insertTalentForm.state===2">
								<image src="https://renovationcdn.jiachuangnet.com/person/p-img2.png" mode="" style="width: 114rpx;height: 93rpx;"></image>
							</view>
						</view>
						<upload ref="certificateImg" :fileListInit="insertTalentForm.certificateImg" v-show="false" :name='certificateImg'  @uploadFile="uploadFile($event,'certificateImg')"></upload>
					</view>
				</view>
				<view class="submit_btn">
					<u-button :loading="load" type="primary" text="修改" v-if="isEdit&&insertTalentForm.state===2" @click="updateTalent"></u-button>
					<u-button :loading="load" type="primary" text="申请入驻" v-if="!isEdit" @click="insertTalent"></u-button>
				</view>
			</view>
			<u-popup :show="showAddExperience"  @close="clearData" mode="top">
			            <view class="showAddExperience">
							<view class="flex alignItem bewteen">
								<view class="label" style="width:200rpx"><text style="color:red;margin-right: 10rx;">*</text>项目名称</view>
								<view class="val">
									<u--input
											v-model="projectDetailForm.projectName"
											border="none"
									></u--input>
								</view>
							</view>
							<view class="flex alignItem bewteen">
								<view class="label" style="width:200rpx"><text style="color:red;margin-right: 10rx;">*</text>时间</view>
								<view class="val">
									<view class="timer_box ">
										<view class="startTime" @click="showStartTimer=true">
											{{projectDetailForm.startTime.length?projectDetailForm.startTime:'开始时间'}}
										</view>
										至
										<view class="endTime" @click="showEndTimer=true">
											{{projectDetailForm.endTime.length?projectDetailForm.endTime:'结束时间'}}
										</view>
									</view>
								</view>
							</view>
							<view class="flex alignItem bewteen">
								<view class="label" style="width:200rpx"><text style="color:red;margin-right: 10rx;">*</text>工作内容</view>
								<view class="val introduce_text" style="border-bottom: unset;">
									<u--textarea  v-model="projectDetailForm.content" placeholder="介绍工作内容" ></u--textarea>
								</view>
							</view>
							<view class="submit_btn" v-if="!isEditExperience">
								<u-button type="primary" text="添加" @click="addExperience"></u-button>
							</view>	
							<view class="submit_btn flex" style="justify-content: space-around;" v-else>
								<view style="width: 40%;">
									<u-button  type="error" text="删除" @click="editHandler(0)"></u-button>
								</view>
								<view style="width: 40%;">
									<u-button  type="primary" text="确定" @click="editHandler(1)"></u-button>
								</view>
							</view>	
			            </view>
			</u-popup>
			<u-popup :show="showViewImg" @close="clearData" >
			            <view class="btn" @click="viewImage">
			                查看图片
			            </view>
						<view class="btn" @click="reLoadImage" >
						    重新上传
						</view>
			</u-popup>
			<u-datetime-picker
			                :show="showStartTimer"
			                v-model="startTime"
			                mode="year-month"
							@close="showStartTimer=false"
							@confirm="confirmTimer($event,'startTime')"
			        ></u-datetime-picker>
			<u-datetime-picker
			                :show="showEndTimer"
			                v-model="endTime"
			                mode="year-month"
							@close="showEndTimer=false"
							@confirm="confirmTimer($event,'endTime')"
			        ></u-datetime-picker>
		</view>
		
</template>

<script>
	export default {
		data() {
			return {
				imgChooseId:0,
				showViewImg:false,
				isEdit:false,
				title:'',
				tips: '',
				seconds: 60,
				insertTalentForm:{
					state:0,//0未审核,1审核,2驳回(修改)
					userName:'',
					roleId:0,
					wechatId:'',
					sex:"",
					age:'',
					nickName:'',
					workYears:'',
					introduction:'',
					phoneNumber:'',
					code:'',
					address:'',
					latitude:'',
					longitude:'',
					avatar:'',
					idCard:'',
					idCardImg:[],
					frontImg:'',
					backImg:'',
					certificateImg:[],
					projectDetail:[],	
				},
				startTime:'',
				endTime:'',
				projectDetailForm:{
					projectName:'',
					startTime:'',
					endTime:'',
					content:''
				},
				sexList:[
					{
						name:'男'
					},
					{
						name:'女'
					},
				],
				roleList:[],
				showAddExperience: false,
				showSex: false,
				showStartTimer:false,
				showEndTimer:false,
				radio: '',
				switchVal: false,
				isEditExperience:false,
				editId:0,
				editIndex:0,
				load:false,
				talentState:''
			};
		},
		onLoad(query){
			if(query.isEdit){
				this.isEdit=query.isEdit
				this.getTalentInfo()
				this.getRoleId()
				this.title='个人信息'
				if(query.talentState){
					this.talentState=query.talentState
					// if(query.talentState==1){
					// 	this.talentState='已认证'
					// 	return uni.$u.toast('审核通过,请勿重复申请:)');
					// }else if(query.talentState==2){
					// 	this.talentState='申请未审核,请耐心等待'
					// 	return uni.$u.toast('申请未审核,请耐心等待:)');
					// }else if(query.talentState==3){
					// 	this.talentState='已驳回'
					// 	return uni.$u.toast('申请已驳回,请重新修改个人信息后再申请:)');
					// }else if(query.talentState==4){
					// 	this.talentState='已禁用'
					// 	return uni.$u.toast('账号被禁用,请联系管理员:)');
					// }
				}
				
			}else{
				this.getRoleId()
				this.insertTalentForm.phoneNumber=uni.getStorageSync('phoneNum')
				this.title='申请入驻'
			}
		},
		methods: {
			updateTalent(){
				if(this.load) return uni.$u.toast('请勿重复操作：)');
				
				if(this.insertTalentForm.wechatId.length&&this.insertTalentForm.sex.length&&this.insertTalentForm.age&&this.insertTalentForm.workYears&&this.insertTalentForm.address.length&&this.insertTalentForm.avatar.length&&this.insertTalentForm.frontImg.length&&this.insertTalentForm.backImg.length&&this.insertTalentForm.certificateImg.length&&this.insertTalentForm.phoneNumber.length&&this.insertTalentForm.projectDetail.length){
					// 由后端根据身份证信息决定nickName
					if(!this.insertTalentForm.introduction.length){
						this.insertTalentForm.introduction='暂无介绍'
					}
					this.load=true
					this.insertTalentForm.nickName=''
					uni.$u.http.post('/talent/updateTalent',this.insertTalentForm).then(res=>{
						if(res){
							uni.$u.toast('修改成功：)');
							// this.getTalentInfo()
							uni.switchTab({
								url: `/pages/mine/index`,
							})
						}
						this.load=false
					})
				}else{
					 uni.$u.toast('请输入完整内容');
				}
			},
			editHandler(flag){
				if(flag){
					// 修改
					this.insertTalentForm.projectDetail[this.editIndex].content=this.projectDetailForm.content
					this.insertTalentForm.projectDetail[this.editIndex].endTime=this.projectDetailForm.endTime
					this.insertTalentForm.projectDetail[this.editIndex].projectName=this.projectDetailForm.projectName
					this.insertTalentForm.projectDetail[this.editIndex].startTime=this.projectDetailForm.startTime
					if(this.isEdit&&this.insertTalentForm.state==1){
						const projectDetailItem=Object.assign({},this.projectDetailForm)
						if(this.verity(projectDetailItem)){
							uni.$u.http.post('/talent/updateProject',{
								projectId:this.editId,
								projectName:this.projectDetailForm.projectName,
								startTime:this.projectDetailForm.startTime,
								endTime:this.projectDetailForm.endTime,
								content:this.projectDetailForm.content
							}).then(res=>{
								uni.$u.toast('修改成功')
							})
						}
						
					}
					this.clearData()
				}else{
					// 删除操作
					this.insertTalentForm.projectDetail.splice(this.editIndex, 1)
					if(this.isEdit&&this.insertTalentForm.state==1){
						uni.$u.http.get('/talent/deleteProjectDetail',{
							params:{
								projectId:this.editId,
							}
						}).then(res=>{
							uni.$u.toast('删除成功')
						})
					}
					this.clearData()
				}
			},
			experienceEdit(index,id){
				if(this.isEdit&&this.insertTalentForm.state==0){
					 return uni.$u.toast('信息尚未审核,不能编辑:)')
				}
				this.isEditExperience=true
				this.showAddExperience=true
				this.editId=id
				this.editIndex=index
				this.projectDetailForm=Object.assign({},this.insertTalentForm.projectDetail[index])
			},
			preImgList(currentIndex){
						uni.previewImage({
							current:currentIndex,
							urls:this.insertTalentForm.certificateImg.map(url=>'http://'+url),
							longPressActions: {
								itemList: ['保存图片'],
								success: data=> {
									console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
									uni.closePreviewImage()
									/* 保存图片到系统相册 */
									if(data.tapIndex==0){
										uni.getImageInfo({
													src:this.insertTalentForm.certificateImg.map(url=>'http://'+url)[data.index],
													success: function(res) {
														console.log(res)
														uni.saveImageToPhotosAlbum({ //保存图片到系统相册。
															filePath:res.path, //图片文件路径
															success: function() {
																uni.showToast({
																	title: '图片保存成功',
																	icon: 'none',
																});
															},
															fail: function(e) {
																console.log(e);
																uni.showToast({
																	title: '图片保存失败',
																	icon: 'none',
																});
															},
														});
													},
													fail: function(e) {
														console.log(e);
														uni.closePreviewImage()
														uni.showToast({
															title: '图片保存失败',
															icon: 'none',
														});
													},
												})
									}
								},
								fail: function(err) {
									console.log(err.errMsg);
								}
							}
						})
			},
			deleteImg(index){
				//证件
				let e={index}
				this.$refs['certificateImg'].deletePic(e)
			},
			viewImage(){
				if(this.imgChooseId==1){
					// 上传身份证正面
					this.viewImgFn(this.insertTalentForm.frontImg)
				}else if(this.imgChooseId==2){
					// 上传身份证反面
					this.viewImgFn(this.insertTalentForm.backImg)
				}else if(this.imgChooseId==4){
					// 上传头像
					this.viewImgFn(this.insertTalentForm.avatar)
				}
			},
			viewImgFn(url){
				uni.previewImage({
					current: 0,
					urls: ['http://'+url],
					longPressActions: {
								itemList: ['保存图片'],
								success: data=> {
									console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
									uni.closePreviewImage()
									/* 保存图片到系统相册 */
									if(data.tapIndex==0){
										uni.getImageInfo({
													src:'http://'+url,
													success: function(res) {
														console.log(res)
														uni.saveImageToPhotosAlbum({ //保存图片到系统相册。
															filePath:res.path, //图片文件路径
															success: function() {
																uni.showToast({
																	title: '图片保存成功',
																	icon: 'none',
																});
															},
															fail: function(e) {
																console.log(e);
																uni.showToast({
																	title: '图片保存失败',
																	icon: 'none',
																});
															},
														});
													},
													fail: function(e) {
														console.log(e);
														uni.closePreviewImage()
														uni.showToast({
															title: '图片保存失败',
															icon: 'none',
														});
													},
												})
									}
								},
								fail: function(err) {
									console.log(err.errMsg);
								}
							}
				});
			},
			reLoadImage(){
				console.log(this.imgChooseId)
				if(this.imgChooseId==1){
					// 上传身份证正面
					this.$refs['frontImg'].clickUpload()
				}else if(this.imgChooseId==2){
					// 上传身份证反面
					this.$refs['backImg'].clickUpload()
				}else if(this.imgChooseId==4){
					// 上传头像
					this.$refs['avatar'].clickUpload()
				}
			},
			viewImgChoose(flag){
				if(this.isEdit&&this.insertTalentForm.state!=2){
					// 只能查看
					this.imgChooseId=flag
					this.viewImage()
					return 
				}
				this.imgChooseId=flag
				this.showViewImg=true
				
			},
			uploadShow(flag){
				if(this.isEdit&&this.insertTalentForm.state!=2) {
					return
				}
				if(flag==1){
					// 上传身份证正面
					this.$refs['frontImg'].clickUpload()
				}else if(flag==2){
					// 上传身份证反面
					this.$refs['backImg'].clickUpload()
				}else if(flag==3){
					//上传证件
					this.$refs['certificateImg'].clickUpload()
				}else{
					// 上传头像
					this.$refs['avatar'].clickUpload()
				}
			},
			getTalentInfo(){
				
				return uni.$u.http.get('/talent/getTalentInfo',{params:{
					userId:uni.getStorageSync('userId')
				}}).then(res=>{
					this.insertTalentForm=res
				})
			},
			map(){
				if(this.isEdit&&this.insertTalentForm.state!=2) {
					return
				}
				uni.chooseLocation({
					type: 'gcj02',
					success: (res) => {
						this.insertTalentForm.latitude = res.latitude;
						this.insertTalentForm.longitude = res.longitude;
						this.insertTalentForm.address = res.address;
					}
				})
			},
			getRoleId(){
				return uni.$u.http.get('/talent/getRoleId').then((res)=>{
					this.roleList=res.map(item=>{
						 return {
							value:item.roleId,
							text:item.roleName
						}
						
					})
				})
			},
			generateCode(){
				return uni.$u.http.get('/user/generateCode',{
					params:{
						phoneNumber:this.insertTalentForm.phoneNumber
					}
				})
			},
			async getCode() {
				if (this.$refs.uCode.canGetCode) {
					if(this.insertTalentForm.phoneNumber.length===0) {
						return uni.$u.toast('请输入电话号码')
					}
					if(uni.$u.test.mobile(this.insertTalentForm.phoneNumber)){
						return uni.$u.toast('电话号码格式错误')
					}
					// 模拟向后端请求验证码
					uni.showLoading({
						title: '正在获取验证码'
					})
					const res= await this.generateCode()
					if(!res) {
						uni.$u.toast('手机号不正确');
						return
					}
					setTimeout(() => {
						uni.hideLoading();
						// 这里此提示会被this.start()方法中的提示覆盖
						uni.$u.toast('验证码已发送');
						// 通知验证码组件内部开始倒计时
						this.$refs.uCode.start();
					}, 60);
				} else {
					uni.$u.toast('倒计时结束后再发送');
				}
			},
			codeChange(text) {
				this.tips = text;
			},
			insertTalent(){
				if(this.load) return uni.$u.toast('请勿重复操作：)');
				
				if(this.insertTalentForm.wechatId.length&&this.insertTalentForm.sex.length&&this.insertTalentForm.age.length&&this.insertTalentForm.workYears.length&&this.insertTalentForm.address.length&&this.insertTalentForm.avatar.length&&this.insertTalentForm.frontImg.length&&this.insertTalentForm.backImg.length&&this.insertTalentForm.certificateImg.length&&this.insertTalentForm.phoneNumber.length&&this.insertTalentForm.projectDetail.length){
					// 由后端根据身份证信息决定nickName
					if(!this.insertTalentForm.introduction.length){
						this.insertTalentForm.introduction='暂无介绍'
					}
					this.load=true
					this.insertTalentForm.nickName=''
					uni.$u.http.post('/talent/insertTalent',this.insertTalentForm).then(res=>{
						if(res){
							uni.setStorageSync('prompt')=='no'
							uni.$u.toast('入驻成功：)');
							uni.switchTab({
								url: `/pages/settled/index`,
							})
							
						}
						this.load=false
					})
				}else{
					 uni.$u.toast('请输入完整内容');
				}
				
			},
			uploadFile(msg,mode){
				if(mode=='certificateImg'){
					return this.insertTalentForm[mode]=msg.files
				}
				this.insertTalentForm[mode]=msg.files[0]||''
				this.clearData()
			},
			clearData(){
				Object.keys(this.projectDetailForm).forEach(key=>{
					if(this.projectDetailForm.hasOwnProperty(key)&&this.projectDetailForm[key].length!=0){
						this.projectDetailForm[key]=''
					}
				})
				this.showViewImg=false
				this.imgChooseId=0
				this.showAddExperience=false
				this.showStartTimer=false
				this.showEndTimer=false
				this.isEditExperience=false
				this.editId=0
				this.editIndex=0
			},
			verity(obj){
				return !Object.keys(obj).some(key=>{
					if(obj.hasOwnProperty(key)&&obj[key].length==0) {
						 uni.$u.toast('请输入完整内容');
						 return true
					}else{
						return false
					}
				})
			},
			addExperience(){
				const projectDetailItem=Object.assign({},this.projectDetailForm)
				if(projectDetailItem.content.length&&projectDetailItem.endTime.length&&projectDetailItem.projectName.length&&projectDetailItem.startTime.length){
					this.insertTalentForm.projectDetail.push(projectDetailItem)
					if(this.isEdit&&this.insertTalentForm.state==1){
						uni.$u.http.post('/talent/insertProjectDetail',{
							projectId:this.editId,
							projectName:this.projectDetailForm.projectName,
							startTime:this.projectDetailForm.startTime,
							endTime:this.projectDetailForm.endTime,
							content:this.projectDetailForm.content
						}).then(res=>{
							uni.$u.toast('添加成功')
							this.getTalentInfo()
						})
					}
					this.showAddExperience=false
					this.clearData()
				}else{
					uni.$u.toast('请输入完整内容');
				}

				
			},
			confirmTimer(e,mode){
				if(mode=="startTime"){
					this.projectDetailForm.startTime=this.$u.timeFormat(e.value, 'yyyy-mm')
					this.showStartTimer=false
					
				}else{
					this.projectDetailForm.endTime=this.$u.timeFormat(e.value, 'yyyy-mm')
					this.showEndTimer=false
				}
			},
			sexSelect(e) {
				this.model1.userInfo.sex = e.name
				this.$refs.uForm.validateField('userInfo.sex')
			},
			
		}
	};
</script>
<style>
	page {
		background: #f8f8f8;
		font-size: 12px;
	}
</style>
<style lang="scss" scoped>
	.btn{
		line-height: 100rpx;
		text-align: center;
		border-bottom: 1px solid #E5E5E5;
		font-weight: 500;
		font-size: 26rpx;
		color: #8A8A8A;
	}
	.showAddExperience{
		padding: 80rpx 10rpx 25rpx 10rpx;
	}
	.avatar_box{
		position: absolute;
		left: 50%;
		top:160rpx;
		transform: translate(-50%,0);
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		z-index: 999;
	}
	.submit_btn{
		border-radius: 44rpx;
		overflow: hidden;
	}
	.post_image_box{
		width: 310rpx;
		height: 228rpx;
		background-color: #F5F5F5;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.experience_wrapper{
		.experience_item:last-child{
			border: unset !important;
		}
	}
	
	.experience_item{
		font-size: 28rpx;
		color: #1E272E;
		font-weight: 500;
		border-bottom: 1px dashed #d2ebec;
		padding-bottom: 31rpx;
		
		.experience_item_projectName{
			font-weight: bold;
			
		}
		.experience_item_title{
			margin: 29rpx 0;
		}
		.experience_item_content{
			font-size: 26rpx;
			color: #8A8A8A;
			line-height: 40rpx;
		}
	}
	.boder_left{
		width: 2rpx;
		height: 26rpx;
		background: #C8C9CF;
		margin: 0 30rpx;
	}
	.placeholder{
		text-align:right;
		// font-weight: 500;
		font-size: 28rpx;
		color: #C8C9CF;
	}
	::v-deep.introduce_text{
		.input-placeholder{
			text-align:left !important; 
			font-weight: 500 !important;
			font-size: 28rpx;
			color: #C8C9CF;
		}
		.u-textarea__field{
			text-align:left !important;
			font-weight: 500 !important;
			font-size: 28rpx;
		}
	}
	::v-deep.info_box{
		.u-input{
			padding: 6rpx 10rpx !important;
			background-color: unset !important; 
		}
		.u-radio-group{
			.u-radio{
				margin-left: 29rpx;
			}
		}
		.uni-select__input-text{
			margin-right: 24rpx;
		}
		.input-placeholder{
			text-align:right;
			font-weight: 500 !important;
			font-size: 28rpx;
			color: #C8C9CF;
		}
		.u-input__content__field-wrapper__field{
			text-align:right !important;
			font-weight: 500 !important;
			font-size: 28rpx;
			color: #C8C9CF;
		}

		.uni-select--disabled{
			background-color: unset !important;
		}
		.u-textarea--disabled{
			background-color: unset !important;
		}
		
		// .uni-mask{
		// 	z-index: 100 !important;
		// }
		
		// .uni-select__selector{
		// 	z-index: 9999 !important;
		// 	background-color: #13989A;
		// 	position: absolute;
		// 	top: 0;
		// }
		// .uni-select__selector-scroll{
		// 	z-index: 110 !important;
		// 	background-color: pink;
		// }
	}
	
	.alignItem{
		
	}
	.label{
		font-weight: 500;
		font-size: 28rpx;
		color: #1E272E;
		width: 150rpx !important;
	}
	.val{
		border-bottom: 1px solid #eee;
		padding: 15rpx 0;
	}
	.info_title{
		align-items: center;
		margin-right: 498rpx;
		margin-top: 30rpx;
		font-weight: bold;
		font-size: 32rpx;
		color: #13989A;
		.boder-left{
			width: 8rpx;
			height: 26rpx;
			background: #13989A;
			border-radius: 4rpx;
		}
		
		
	}
	
	
	.flex{
		display: flex;
		justify-content: space-between;
	}
	.container /deep/ .uni-select {
		border: none !important;
		
	}
	.bg {
		width: 750rpx;
		height: 591rpx;
		position: absolute;
		top: 0;
		left: 0;
		z-index: 1;
	}
	.container{
		padding: 0;
		position: absolute;
		top: 437rpx;
		left: 25rpx;
		right: 25rpx;
		z-index: 2;
		// min-height: 100vh;
		padding-bottom: 45rpx;
	}
	.info_box,.certificates_unload,.experience_box{
		background: #FFFFFF;
		border-radius: 20rpx;
		padding: 10rpx 30rpx;
		margin-bottom: 21rpx;
		min-height: 360rpx;
	}
	.container /deep/ .uni-select__input-placeholder {
		font-size: 28rpx !important;
		color: #c7ccd3;
		text-align: right;
	}
		
	.timer_box{
		display: flex;
		align-items: center;
	}
	
	.startTime,.endTime{
		line-height: 50rpx;
		border: 1px solid #c7ccd3;
		padding: 12rpx 10rpx;
		
	}
</style>